package org.flowers.unbeaten.exception;

import org.flowers.unbeaten.exception.code.BaseResponseCode;
import org.flowers.unbeaten.exception.code.ResponseCode;

/**
 * @description 业务异常
 * @author RyanWang
 * @date 2021-07-16 13:34:59
 * @version 1.0
 */
public class BusinessException extends RuntimeException {

    private final int messageCode;

    private final String messageDetail;


    public BusinessException(int messageCode, String messageDetail) {
        super(messageDetail);
        this.messageCode = messageCode;
        this.messageDetail = messageDetail;
    }

    public BusinessException(String messageDetail) {
        super(messageDetail);
        this.messageCode = BaseResponseCode.FAILURE.getCode();
        this.messageDetail = messageDetail;
    }

    /**
     * 构造函数
     * @param code
     */
    public BusinessException(ResponseCode code) {
        this(code.getCode(), code.getMessage());
    }

    public int getMessageCode() {
        return messageCode;
    }

    public String getMessageDetail() {
        return messageDetail;
    }

}
